module GrapeAPI
  module ApiHelpers

    def error_30!(msg = nil)
      status 400
      {
        :status => 30,
        :msg => msg.blank? ? "Internal server error." : msg
      }
    end

    def responses_200!(msg = nil)
      status 200
      header "Access-Control-Allow-Origin","*"
      unless msg.blank?
        msg
      else
        {
          :msg =>  "success."
        }
      end
    end

    def responses_201!(msg = nil)
      status 201
      puts "=====msg ======#{msg}"
      unless msg.blank?
        msg
      else
        {
          :msg =>  "success."
        }
      end
    end

    def logger(data)
      Rails.logger.info("======>#{data}")
    end

    def current_user(object_id, signature)
      _h5time_user = H5timeUsers.getH5timeUsers(object_id, signature)
      if _h5time_user.blank?
        false
      else
        true
      end
    end
  end
end
